<template>
  <div id="view-message">
    <Aside :menuItems="asideAttrs.menuItems" :title="asideAttrs.title">
      <MessageList v-bind:messageList="messageList"></MessageList>
    </Aside>
  </div>
</template>


<script>
import MessageList from "./messageList";
import RequestUtil from "../../utils/requestUtils";
import Aside from "../../components/aside/aside"

export default {
  name: "Message",
  components: {
    MessageList,
    Aside,
  },
  data() {
    return {
      linkMy: sessionStorage.getItem('id') == null ? "/login" : "/my",
      collapsed: false,
      messageList: [],
      asideAttrs: {
        title: "WeParty",
        menuItems: [
          {
            iconType: "message",
            iconTheme: "filled",
            name: "message",
            link: "",
          },
          {
            iconType: "flag",
            iconTheme: "filled",
            name: "Publish Activity",
            link: sessionStorage.getItem("id") ? "/publish" : "/login",
          },
        ],
      },
    };
  },
  methods: {
    onSearch() {
      console.log("call onSearch()");
    },
    getNowTime() {
      var date = new Date();
      this.year = date.getFullYear();
      this.month = date.getMonth() + 1;
      this.date = date.getDate();
      this.hour =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      this.minute =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      this.second =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      var currentTime =
        this.year +
        "-" +
        this.month +
        "-" +
        this.date +
        " " +
        this.hour +
        ":" +
        this.minute +
        ":" +
        this.second;
      return currentTime;
    },
  },
  mounted: function () {
    console.log("mounted");
    let that = this;
 
    let result = RequestUtil.requestMessage(
      that,
      sessionStorage.getItem('id'),
      "passing",
      (res) => {
        console.log(res);
        if (res.status == 200) {
          let data = res.data;

          //检查error_code
          if (data.error_code == 0) {
            // 返回数据
            let result = data.result;
            // 添加时间
            result.forEach((element) => {
              element.activityInfoVo.time = that.getNowTime();
            });
            that.messageList = result;
            that.$message.success("成功拉取消息列表");
          } else {
            console.error(`error_code: ${data.error_code}`);
            console.error(`error_msg: ${data.error_msg}`);
          }
        } else {
          console.error(`res.status: ${res.status}`);
        }
      },
      (err) => {
        console.error(err);
        that.$message.error("获取消息列表失败");
      }
    );
    console.error(result);
  },
};
</script>

<style lang="less" scope>
.center() {
  align-items: center;
  justify-content: center;
}

#view-message {
  height: 100%;
}

// #component-aside {
//   height: 100%;
//   width: 100%;
// }

// #components-layout-demo-custom-trigger {
//   height: 100%;
//   .trigger {
//     font-size: 18px;
//     line-height: 64px;
//     padding: 0 24px;
//     cursor: pointer;
//     transition: color 0.3s;
//     &:hover {
//       color: #1890ff;
//     }
//   }
//   .my {
//     float: right;
//     margin: 16px 48px 16px 0;
//   }
//   .logo {
//     display: flex;
//     .center();
//     height: 32px;
//     background: rgba(255, 255, 255, 0.2);
//     margin: 16px;
//     span {
//       font-size: 16px;
//     }
//   }
// }

.message-list {
  width: 100%;
}
</style>